var t = require("../../@babel/runtime/helpers/interopRequireDefault")(require("../../@babel/runtime/helpers/defineProperty")), e = require("../../services/api.js"), a = require("../../utils/util.js"), n = require("../../services/baseURL.js");

Page({
    data: {
        answer: [ -1, -1, -1 ],
        qa: [ "味道好吗？", "分量合适吗？", "产品有撒漏吗？" ],
        text: "",
        order: "",
        money: "",
        upload: []
    },
    onLoad: function(t) {
        t.id ? this.getDetail(t.id) : wx.showModal({
            title: "提示",
            content: "无效的凭证",
            showCancel: !1,
            success: function() {
                wx.navigateTo();
            }
        });
    },
    optionChange: function(e) {
        var a = e.currentTarget.dataset, n = a.id, i = a.type;
        this.setData((0, t.default)({}, "answer[".concat(n, "]"), i));
    },
    giveUpTask: function() {
        var t = this;
        wx.showModal({
            title: "提示",
            content: "确定放弃任务吗？",
            confirmText: "放弃",
            cancelText: "再考虑",
            success: function(a) {
                a.confirm && (0, e.taskQuit)({
                    t_m_id: t.data.info.stage.tmi_id
                }).then(function(e) {
                    200 === e.data.code ? (wx.showToast({
                        title: "操作成功",
                        mask: !0
                    }), setTimeout(function() {
                        wx.navigateBack();
                    }, 1e3)) : wx.showModal({
                        title: "提示",
                        content: e.data.message,
                        showCancel: !1
                    }), t.getDetail();
                });
            }
        });
    },
    qaInput: function(t) {
        this.setData({
            text: t.detail.value
        });
    },
    orderInput: function(t) {
        this.setData({
            order: t.detail.value
        });
    },
    moneyInput: function(t) {
        this.setData({
            money: t.detail.value
        });
    },
    chooseImage: function() {
        var t = this;
        wx.chooseMedia({
            mediaType: [ "image" ],
            sizeType: [ "compressed" ],
            count: 0 == this.data.status ? 2 : 1,
            success: function(e) {
                t.setData({
                    upload: [].concat(t.data.upload, e.tempFiles)
                });
            },
            fail: function() {
                wx.showModal({
                    title: "提示",
                    content: "图片选择失败",
                    showCancel: !1
                });
            }
        });
    },
    onReady: function() {},
    send: function() {
        var t = this.data.status, a = this.data, n = (a.text, a.order), i = a.money, o = a.upload, s = a.info.stage.tmi_id, c = {};
        if (0 == t) {
            if (c = {
                takeaway_order: n,
                takeaway_price: i,
                first_thumb: o
            }, 0 == n.trim().length) return void wx.showModal({
                title: "提示",
                content: "请填写订单编号",
                showCancel: !1
            });
            if (0 == i.trim().length) return void wx.showModal({
                title: "提示",
                content: "请填写支付金额",
                showCancel: !1
            });
            if (0 == o.length) return void wx.showModal({
                title: "提示",
                content: "请选择上传凭证",
                showCancel: !1
            });
        } else {
            if (2 != t) return void wx.showModal({
                title: "提示",
                content: "该单已提交凭证",
                showCancel: !1,
                success: function() {
                    wx.switchTab({
                        url: "/pages/index/index"
                    });
                }
            });
            if (c = {
                finally_thumb: o
            }, 0 == o.length) return void wx.showModal({
                title: "提示",
                content: "请选择好评截图",
                showCancel: !1
            });
        }
        wx.showLoading({
            title: "上传中",
            mask: !0
        }), this.uploadF(o).then(function(t) {
            c.finally_thumb && (c.finally_thumb = t), c.first_thumb && (c.first_thumb = t), 
            c.t_m_id = s, (0, e.uoloadOrder)(c).then(function(t) {
                wx.hideLoading(), 200 === t.data.code ? (wx.showToast({
                    title: "上传成功",
                    mask: !0,
                    duration: 1500
                }), setTimeout(function() {
                    wx.navigateBack();
                }, 1e3)) : wx.showModal({
                    title: "提示",
                    content: t.data.message,
                    showCancel: !1
                });
            }).catch(function(t) {
                wx.hideLoading(), wx.showModal({
                    title: "提示",
                    content: t.toString()
                });
            });
        }).catch(function(t) {
            wx.hideLoading(), wx.showModal({
                title: "提示",
                content: t.toString()
            });
        });
    },
    uploadF: function(t) {
        var e = (0, a.getAuth)(), i = t.map(function(t) {
            return new Promise(function(a, i) {
                wx.uploadFile({
                    url: "".concat(n.baseURL, "/v1/file/images"),
                    filePath: t.tempFilePath,
                    header: {
                        "x-api-key": e.value
                    },
                    name: "file",
                    success: function(t) {
                        var e = JSON.parse(t.data);
                        200 === e.code ? a(e.data.url) : i(e.message);
                    }
                });
            });
        });
        return Promise.all(i);
    },
    getDetail: function(t) {
        var n = this, i = (0, a.getLocation)();
        i || (i = {
            name: "成都",
            latitude: "30.657446",
            longitude: "104.065746"
        }), (0, e.getTaskDetail)({
            id: t,
            lng: i.longitude,
            lat: i.latitude
        }).then(function(t) {
            if (200 === t.data.code) {
                var e = t.data.data, i = (0, a.getOrderStatus)(e);
                n.setData({
                    info: e,
                    status: i
                }), 0 !== i && 2 !== i && 4 !== i && wx.showModal({
                    title: "提示",
                    content: "请等待订单审核完毕",
                    showCancel: !1,
                    success: function() {
                        wx.switchTab({
                            url: "/pages/index/index"
                        });
                    }
                });
            } else wx.showModal({
                title: "提示",
                content: "无效商品",
                showCancel: !1,
                success: function() {
                    wx.switchTab({
                        url: "/pages/index/index"
                    });
                }
            });
        });
    },
    onShow: function() {},
    onHide: function() {},
    inputClear: function(t) {
        var e = this.data.upload;
        e.splice(t.currentTarget.dataset.id, 1), this.setData({
            upload: e
        });
    },
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {}
});